
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>3.7：输入框和表单 · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://pcdn.flutterchina.club/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://pcdn.flutterchina.club/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="progress.html" />
    
    
    <link rel="prev" href="radio_and_checkbox.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 8px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .f-links a{
            text-decoration: underline;
            color: dodgerblue !important;
        }

        .f-links a:hover{
            opacity: .8 !important;
        }

        /*.ad {*/
            /*color: white;*/
            /*text-align: center;*/
            /*background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);*/
            /*background-size: cover;*/
            /*cursor: pointer;*/
            /*margin-bottom: 30px;*/
            /*padding: 18px*/
        /*}*/

        /*.ad:hover {*/
            /*opacity: .8;*/
        /*}*/

        .buy-btn {
            text-decoration: none !important;
            padding: 8px 18px;
            border: #268bd2 1px solid !important;
            display: inline-block !important;
            border-radius: 25px;
            color: #268bd2;
            margin-top: 10px;
        }

        .buy-btn:hover {
            transition: all ease 200ms;
            box-shadow: #555 2px 5px 10px;
            background: #eee;
            color: dodgerblue !important;
        }

        .maoyun{
            padding-top: 5px;
        }


    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
<!--<div class="ad ad0"-->
<!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
<!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
<!--</div>-->
<!--<div class="ad ad1"-->
<!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
<!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
<!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
<!--</div>-->
<!--</div>-->

<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('btn')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a></div>


<!--<div class="ad"  style="text-align:center; padding-bottom:30px; display: none"><a href="https://item.jd.com/12816296.html" onclick="buy('img')" title='点击购买' target="_blank"><img style="height:250px;box-shadow: #aaa 5px 5px 10px;" src="https://pcdn.flutterchina.club/imgs/book.png"/></a>  <br/> <a class="buy-btn" onclick="buy('img')" href="https://item.jd.com/12816296.html" title='点击购买' target="_blank"> 购买实体书 </a>-->
    <!--<a id="jd" href="https://item.jd.com/12816296.html" onclick="buy('jd')"  style=" display: block; padding: 10px; color: red; text-decoration: underline; ">即日起至4.23日，京东图书每满100减50！ </a>-->
<!--</div>-->


<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../intro.html">
            
                <a href="../intro.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">入门篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    第一章：起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    1.1：移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    1.2：初识Flutter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    1.3：搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    1.4：Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第二章：第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    2.1：计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    2.2：路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    2.3：包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    2.4：资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    2.5：调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    2.6：Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="./">
            
                <a href="./">
            
                    
                    第三章：基础组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="flutter_widget_intro.html">
            
                <a href="flutter_widget_intro.html">
            
                    
                    3.1：Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="state_manage.html">
            
                <a href="state_manage.html">
            
                    
                    3.2：状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="text.html">
            
                <a href="text.html">
            
                    
                    3.3：文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="buttons.html">
            
                <a href="buttons.html">
            
                    
                    3.4：按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="img_and_icon.html">
            
                <a href="img_and_icon.html">
            
                    
                    3.5：图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="radio_and_checkbox.html">
            
                <a href="radio_and_checkbox.html">
            
                    
                    3.6：单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="2.3.7" data-path="input_and_form.html">
            
                <a href="input_and_form.html">
            
                    
                    3.7：输入框和表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="progress.html">
            
                <a href="progress.html">
            
                    
                    3.8：进度指示器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    第四章：布局类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    4.1：布局类组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    4.2：线性布局（Row、Column）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    4.3：弹性布局（Flex）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    4.4：流式布局（Wrap、Flow）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    4.5：层叠布局（Stack、Positioned）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.6" data-path="../chapter4/alignment.html">
            
                <a href="../chapter4/alignment.html">
            
                    
                    4.6：对齐与相对定位（Align）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    第五章：容器类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    5.1：填充（Padding）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    5.2：尺寸限制类容器（ConstrainedBox等）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    5.3：装饰容器（DecoratedBox）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    5.4：变换（Transform）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    5.5：Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    5.6：Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.7" data-path="../chapter5/clip.html">
            
                <a href="../chapter5/clip.html">
            
                    
                    5.7：剪裁（Clip）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    第六章：可滚动组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../chapter6/intro.html">
            
                <a href="../chapter6/intro.html">
            
                    
                    6.1：可滚动组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../chapter6/single_child_scrollview.html">
            
                <a href="../chapter6/single_child_scrollview.html">
            
                    
                    6.2：SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../chapter6/listview.html">
            
                <a href="../chapter6/listview.html">
            
                    
                    6.3：ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../chapter6/gridview.html">
            
                <a href="../chapter6/gridview.html">
            
                    
                    6.4：GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../chapter6/custom_scrollview.html">
            
                <a href="../chapter6/custom_scrollview.html">
            
                    
                    6.5：CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../chapter6/scroll_controller.html">
            
                <a href="../chapter6/scroll_controller.html">
            
                    
                    6.6：滚动监听及控制（ScrollController）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    第七章：功能型组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    7.1：导航返回拦截（WillPopScope）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    7.2：数据共享（InheritedWidget）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="../chapter7/provider.html">
            
                <a href="../chapter7/provider.html">
            
                    
                    7.3： 跨组件状态共享（Provider）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    7.4：颜色和主题（Theme）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.5" data-path="../chapter7/futurebuilder_and_streambuilder.html">
            
                <a href="../chapter7/futurebuilder_and_streambuilder.html">
            
                    
                    7.5：异步UI更新（FutureBuilder、StreamBuilder）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.6" data-path="../chapter7/dailog.html">
            
                <a href="../chapter7/dailog.html">
            
                    
                    7.6：对话框详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    第八章：事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../chapter8/listener.html">
            
                <a href="../chapter8/listener.html">
            
                    
                    8.1：原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../chapter8/gesture.html">
            
                <a href="../chapter8/gesture.html">
            
                    
                    8.2：手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../chapter8/eventbus.html">
            
                <a href="../chapter8/eventbus.html">
            
                    
                    8.3：全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../chapter8/notification.html">
            
                <a href="../chapter8/notification.html">
            
                    
                    8.4：通知(Notification)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    第九章：动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    9.1：Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    9.2：动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    9.3：自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    9.4：Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    9.5：交织动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../chapter9/animated_switcher.html">
            
                <a href="../chapter9/animated_switcher.html">
            
                    
                    9.6：通用“动画切换”组件（AnimatedSwitcher）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../chapter9/animated_widgets.html">
            
                <a href="../chapter9/animated_widgets.html">
            
                    
                    9.7：动画过渡组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    第十章：自定义组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../chapter10/intro.html">
            
                <a href="../chapter10/intro.html">
            
                    
                    10.1：自定义组件方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../chapter10/combine.html">
            
                <a href="../chapter10/combine.html">
            
                    
                    10.2：组合现有组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../chapter10/turn_box.html">
            
                <a href="../chapter10/turn_box.html">
            
                    
                    10.3：组合实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../chapter10/custom_paint.html">
            
                <a href="../chapter10/custom_paint.html">
            
                    
                    10.4：自绘组件（CustomPaint与Canvas）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../chapter10/gradient_circular_progress_demo.html">
            
                <a href="../chapter10/gradient_circular_progress_demo.html">
            
                    
                    10.5：自绘实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../chapter11/">
            
                <a href="../chapter11/">
            
                    
                    第十一章：文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../chapter11/file_operation.html">
            
                <a href="../chapter11/file_operation.html">
            
                    
                    11.1：文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../chapter11/http.html">
            
                <a href="../chapter11/http.html">
            
                    
                    11.2：Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../chapter11/dio.html">
            
                <a href="../chapter11/dio.html">
            
                    
                    11.3：Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../chapter11/download_with_chunks.html">
            
                <a href="../chapter11/download_with_chunks.html">
            
                    
                    11.4：实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../chapter11/websocket.html">
            
                <a href="../chapter11/websocket.html">
            
                    
                    11.5：WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../chapter11/socket.html">
            
                <a href="../chapter11/socket.html">
            
                    
                    11.6：使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.7" data-path="../chapter11/json_model.html">
            
                <a href="../chapter11/json_model.html">
            
                    
                    11.7：Json转Dart Model类
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    第十二章：包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="../chapter12/develop_package.html">
            
                <a href="../chapter12/develop_package.html">
            
                    
                    12.1：开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="../chapter12/platform-channel.html">
            
                <a href="../chapter12/platform-channel.html">
            
                    
                    12.2：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="../chapter12/develop_plugin.html">
            
                <a href="../chapter12/develop_plugin.html">
            
                    
                    12.3：开发Flutter插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="../chapter12/android_implement.html">
            
                <a href="../chapter12/android_implement.html">
            
                    
                    12.4：插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="../chapter12/ios_implement.html">
            
                <a href="../chapter12/ios_implement.html">
            
                    
                    12.5：插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="../chapter12/texture_platformview.html">
            
                <a href="../chapter12/texture_platformview.html">
            
                    
                    12.6：Texture和PlatformView
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    第十三章：国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../chapter13/multi_languages_support.html">
            
                <a href="../chapter13/multi_languages_support.html">
            
                    
                    13.1：让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../chapter13/locallization_implement.html">
            
                <a href="../chapter13/locallization_implement.html">
            
                    
                    13.2：实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../chapter13/intl.html">
            
                <a href="../chapter13/intl.html">
            
                    
                    13.3：使用Intl包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../chapter13/faq.html">
            
                <a href="../chapter13/faq.html">
            
                    
                    13.4：国际化常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../chapter14/">
            
                <a href="../chapter14/">
            
                    
                    第十四章：Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../chapter14/flutter_ui_system.html">
            
                <a href="../chapter14/flutter_ui_system.html">
            
                    
                    14.1：Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../chapter14/element_buildcontext.html">
            
                <a href="../chapter14/element_buildcontext.html">
            
                    
                    14.2：Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="../chapter14/render_object.html">
            
                <a href="../chapter14/render_object.html">
            
                    
                    14.3：RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="../chapter14/flutter_app_startup.html">
            
                <a href="../chapter14/flutter_app_startup.html">
            
                    
                    14.4：Flutter从启动到显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.5" data-path="../chapter14/image_and_cache.html">
            
                <a href="../chapter14/image_and_cache.html">
            
                    
                    14.5：Flutter图片加载与缓存
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实例篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    第十五章：一个完整的Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="../chapter15/intro.html">
            
                <a href="../chapter15/intro.html">
            
                    
                    15.1：应用简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="../chapter15/code_structure.html">
            
                <a href="../chapter15/code_structure.html">
            
                    
                    15.2：APP代码结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="../chapter15/models.html">
            
                <a href="../chapter15/models.html">
            
                    
                    15.3：Model类定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="../chapter15/globals.html">
            
                <a href="../chapter15/globals.html">
            
                    
                    15.4：全局变量及共享状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="../chapter15/network.html">
            
                <a href="../chapter15/network.html">
            
                    
                    15.5：网络请求封装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.6" data-path="../chapter15/entry.html">
            
                <a href="../chapter15/entry.html">
            
                    
                    15.6：App入口及首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="../chapter15/login_page.html">
            
                <a href="../chapter15/login_page.html">
            
                    
                    15.7：登录页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="../chapter15/language_and_theme_setting.html">
            
                <a href="../chapter15/language_and_theme_setting.html">
            
                    
                    15.8：多语言和多主题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="https://pcdn.flutterchina.club/gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3.7：输入框和表单</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="37-&#x8F93;&#x5165;&#x6846;&#x53CA;&#x8868;&#x5355;">3.7 &#x8F93;&#x5165;&#x6846;&#x53CA;&#x8868;&#x5355;</h1>
<p>Material&#x7EC4;&#x4EF6;&#x5E93;&#x4E2D;&#x63D0;&#x4F9B;&#x4E86;&#x8F93;&#x5165;&#x6846;&#x7EC4;&#x4EF6;<code>TextField</code>&#x548C;&#x8868;&#x5355;&#x7EC4;&#x4EF6;<code>Form</code>&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x5206;&#x522B;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x3002;</p>
<h2 id="371-textfield">3.7.1 TextField</h2>
<p><code>TextField</code>&#x7528;&#x4E8E;&#x6587;&#x672C;&#x8F93;&#x5165;&#xFF0C;&#x5B83;&#x63D0;&#x4F9B;&#x4E86;&#x5F88;&#x591A;&#x5C5E;&#x6027;&#xFF0C;&#x6211;&#x4EEC;&#x5148;&#x7B80;&#x5355;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#x4E3B;&#x8981;&#x5C5E;&#x6027;&#x7684;&#x4F5C;&#x7528;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;&#x51E0;&#x4E2A;&#x793A;&#x4F8B;&#x6765;&#x6F14;&#x793A;&#x4E00;&#x4E0B;&#x5173;&#x952E;&#x5C5E;&#x6027;&#x7684;&#x7528;&#x6CD5;&#x3002;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">const</span> <span class="token function">TextField</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
  TextEditingController controller<span class="token punctuation">,</span> 
  FocusNode focusNode<span class="token punctuation">,</span>
  InputDecoration decoration <span class="token operator">=</span> <span class="token keyword">const</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  TextInputType keyboardType<span class="token punctuation">,</span>
  TextInputAction textInputAction<span class="token punctuation">,</span>
  TextStyle style<span class="token punctuation">,</span>
  TextAlign textAlign <span class="token operator">=</span> TextAlign<span class="token punctuation">.</span>start<span class="token punctuation">,</span>
  bool autofocus <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
  bool obscureText <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
  int maxLines <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">,</span>
  int maxLength<span class="token punctuation">,</span>
  bool maxLengthEnforced <span class="token operator">=</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
  ValueChanged<span class="token operator">&lt;</span>String<span class="token operator">&gt;</span> onChanged<span class="token punctuation">,</span>
  VoidCallback onEditingComplete<span class="token punctuation">,</span>
  ValueChanged<span class="token operator">&lt;</span>String<span class="token operator">&gt;</span> onSubmitted<span class="token punctuation">,</span>
  List<span class="token operator">&lt;</span>TextInputFormatter<span class="token operator">&gt;</span> inputFormatters<span class="token punctuation">,</span>
  bool enabled<span class="token punctuation">,</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>cursorWidth <span class="token operator">=</span> <span class="token number">2.0</span><span class="token punctuation">,</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>cursorRadius<span class="token punctuation">,</span>
  <span class="token keyword">this</span><span class="token punctuation">.</span>cursorColor<span class="token punctuation">,</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<ul>
<li><p><code>controller</code>&#xFF1A;&#x7F16;&#x8F91;&#x6846;&#x7684;&#x63A7;&#x5236;&#x5668;&#xFF0C;&#x901A;&#x8FC7;&#x5B83;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;/&#x83B7;&#x53D6;&#x7F16;&#x8F91;&#x6846;&#x7684;&#x5185;&#x5BB9;&#x3001;&#x9009;&#x62E9;&#x7F16;&#x8F91;&#x5185;&#x5BB9;&#x3001;&#x76D1;&#x542C;&#x7F16;&#x8F91;&#x6587;&#x672C;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;&#x3002;&#x5927;&#x591A;&#x6570;&#x60C5;&#x51B5;&#x4E0B;&#x6211;&#x4EEC;&#x90FD;&#x9700;&#x8981;&#x663E;&#x5F0F;&#x63D0;&#x4F9B;&#x4E00;&#x4E2A;<code>controller</code>&#x6765;&#x4E0E;&#x6587;&#x672C;&#x6846;&#x4EA4;&#x4E92;&#x3002;&#x5982;&#x679C;&#x6CA1;&#x6709;&#x63D0;&#x4F9B;<code>controller</code>&#xFF0C;&#x5219;<code>TextField</code>&#x5185;&#x90E8;&#x4F1A;&#x81EA;&#x52A8;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x3002;</p>
</li>
<li><p><code>focusNode</code>&#xFF1A;&#x7528;&#x4E8E;&#x63A7;&#x5236;<code>TextField</code>&#x662F;&#x5426;&#x5360;&#x6709;&#x5F53;&#x524D;&#x952E;&#x76D8;&#x7684;&#x8F93;&#x5165;&#x7126;&#x70B9;&#x3002;&#x5B83;&#x662F;&#x6211;&#x4EEC;&#x548C;&#x952E;&#x76D8;&#x4EA4;&#x4E92;&#x7684;&#x4E00;&#x4E2A;&#x53E5;&#x67C4;&#xFF08;handle&#xFF09;&#x3002;</p>
</li>
<li><p><code>InputDecoration</code>&#xFF1A;&#x7528;&#x4E8E;&#x63A7;&#x5236;<code>TextField</code>&#x7684;&#x5916;&#x89C2;&#x663E;&#x793A;&#xFF0C;&#x5982;&#x63D0;&#x793A;&#x6587;&#x672C;&#x3001;&#x80CC;&#x666F;&#x989C;&#x8272;&#x3001;&#x8FB9;&#x6846;&#x7B49;&#x3002;</p>
</li>
<li><p><code>keyboardType</code>&#xFF1A;&#x7528;&#x4E8E;&#x8BBE;&#x7F6E;&#x8BE5;&#x8F93;&#x5165;&#x6846;&#x9ED8;&#x8BA4;&#x7684;&#x952E;&#x76D8;&#x8F93;&#x5165;&#x7C7B;&#x578B;&#xFF0C;&#x53D6;&#x503C;&#x5982;&#x4E0B;&#xFF1A;</p>
</li>
</ul>
<table>
<thead>
<tr>
<th>TextInputType&#x679A;&#x4E3E;&#x503C;</th>
<th>&#x542B;&#x4E49;</th>
</tr>
</thead>
<tbody>
<tr>
<td>text</td>
<td>&#x6587;&#x672C;&#x8F93;&#x5165;&#x952E;&#x76D8;</td>
</tr>
<tr>
<td>multiline</td>
<td>&#x591A;&#x884C;&#x6587;&#x672C;&#xFF0C;&#x9700;&#x548C;maxLines&#x914D;&#x5408;&#x4F7F;&#x7528;(&#x8BBE;&#x4E3A;null&#x6216;&#x5927;&#x4E8E;1)</td>
</tr>
<tr>
<td>number</td>
<td>&#x6570;&#x5B57;&#xFF1B;&#x4F1A;&#x5F39;&#x51FA;&#x6570;&#x5B57;&#x952E;&#x76D8;</td>
</tr>
<tr>
<td>phone</td>
<td>&#x4F18;&#x5316;&#x540E;&#x7684;&#x7535;&#x8BDD;&#x53F7;&#x7801;&#x8F93;&#x5165;&#x952E;&#x76D8;&#xFF1B;&#x4F1A;&#x5F39;&#x51FA;&#x6570;&#x5B57;&#x952E;&#x76D8;&#x5E76;&#x663E;&#x793A;&#x201C;* #&#x201D;</td>
</tr>
<tr>
<td>datetime</td>
<td>&#x4F18;&#x5316;&#x540E;&#x7684;&#x65E5;&#x671F;&#x8F93;&#x5165;&#x952E;&#x76D8;&#xFF1B;Android&#x4E0A;&#x4F1A;&#x663E;&#x793A;&#x201C;: -&#x201D;</td>
</tr>
<tr>
<td>emailAddress</td>
<td>&#x4F18;&#x5316;&#x540E;&#x7684;&#x7535;&#x5B50;&#x90AE;&#x4EF6;&#x5730;&#x5740;&#xFF1B;&#x4F1A;&#x663E;&#x793A;&#x201C;@ .&#x201D;</td>
</tr>
<tr>
<td>url</td>
<td>&#x4F18;&#x5316;&#x540E;&#x7684;url&#x8F93;&#x5165;&#x952E;&#x76D8;&#xFF1B; &#x4F1A;&#x663E;&#x793A;&#x201C;/ .&#x201D;</td>
</tr>
</tbody>
</table>
<ul>
<li><p><code>textInputAction</code>&#xFF1A;&#x952E;&#x76D8;&#x52A8;&#x4F5C;&#x6309;&#x94AE;&#x56FE;&#x6807;(&#x5373;&#x56DE;&#x8F66;&#x952E;&#x4F4D;&#x56FE;&#x6807;)&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x679A;&#x4E3E;&#x503C;&#xFF0C;&#x6709;&#x591A;&#x4E2A;&#x53EF;&#x9009;&#x503C;&#xFF0C;&#x5168;&#x90E8;&#x7684;&#x53D6;&#x503C;&#x5217;&#x8868;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x67E5;&#x770B;API&#x6587;&#x6863;&#xFF0C;&#x4E0B;&#x9762;&#x662F;&#x5F53;&#x503C;&#x4E3A;<code>TextInputAction.search</code>&#x65F6;&#xFF0C;&#x539F;&#x751F;Android&#x7CFB;&#x7EDF;&#x4E0B;&#x952E;&#x76D8;&#x6837;&#x5F0F;&#x5982;&#x56FE;3-24&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-24.png" alt="&#x56FE;3-24"></p>
</li>
<li><p><code>style</code>&#xFF1A;&#x6B63;&#x5728;&#x7F16;&#x8F91;&#x7684;&#x6587;&#x672C;&#x6837;&#x5F0F;&#x3002;</p>
</li>
<li><p><code>textAlign</code>: &#x8F93;&#x5165;&#x6846;&#x5185;&#x7F16;&#x8F91;&#x6587;&#x672C;&#x5728;&#x6C34;&#x5E73;&#x65B9;&#x5411;&#x7684;&#x5BF9;&#x9F50;&#x65B9;&#x5F0F;&#x3002;</p>
</li>
<li><p><code>autofocus</code>: &#x662F;&#x5426;&#x81EA;&#x52A8;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#x3002;</p>
</li>
<li><p><code>obscureText</code>&#xFF1A;&#x662F;&#x5426;&#x9690;&#x85CF;&#x6B63;&#x5728;&#x7F16;&#x8F91;&#x7684;&#x6587;&#x672C;&#xFF0C;&#x5982;&#x7528;&#x4E8E;&#x8F93;&#x5165;&#x5BC6;&#x7801;&#x7684;&#x573A;&#x666F;&#x7B49;&#xFF0C;&#x6587;&#x672C;&#x5185;&#x5BB9;&#x4F1A;&#x7528;&#x201C;&#x2022;&#x201D;&#x66FF;&#x6362;&#x3002;</p>
</li>
<li><p><code>maxLines</code>&#xFF1A;&#x8F93;&#x5165;&#x6846;&#x7684;&#x6700;&#x5927;&#x884C;&#x6570;&#xFF0C;&#x9ED8;&#x8BA4;&#x4E3A;1&#xFF1B;&#x5982;&#x679C;&#x4E3A;<code>null</code>&#xFF0C;&#x5219;&#x65E0;&#x884C;&#x6570;&#x9650;&#x5236;&#x3002;</p>
</li>
<li><p><code>maxLength</code>&#x548C;<code>maxLengthEnforced</code> &#xFF1A;<code>maxLength</code>&#x4EE3;&#x8868;&#x8F93;&#x5165;&#x6846;&#x6587;&#x672C;&#x7684;&#x6700;&#x5927;&#x957F;&#x5EA6;&#xFF0C;&#x8BBE;&#x7F6E;&#x540E;&#x8F93;&#x5165;&#x6846;&#x53F3;&#x4E0B;&#x89D2;&#x4F1A;&#x663E;&#x793A;&#x8F93;&#x5165;&#x7684;&#x6587;&#x672C;&#x8BA1;&#x6570;&#x3002;<code>maxLengthEnforced</code>&#x51B3;&#x5B9A;&#x5F53;&#x8F93;&#x5165;&#x6587;&#x672C;&#x957F;&#x5EA6;&#x8D85;&#x8FC7;<code>maxLength</code>&#x65F6;&#x662F;&#x5426;&#x963B;&#x6B62;&#x8F93;&#x5165;&#xFF0C;&#x4E3A;<code>true</code>&#x65F6;&#x4F1A;&#x963B;&#x6B62;&#x8F93;&#x5165;&#xFF0C;&#x4E3A;<code>false</code>&#x65F6;&#x4E0D;&#x4F1A;&#x963B;&#x6B62;&#x8F93;&#x5165;&#x4F46;&#x8F93;&#x5165;&#x6846;&#x4F1A;&#x53D8;&#x7EA2;&#x3002;</p>
</li>
<li><p><code>onChange</code>&#xFF1A;&#x8F93;&#x5165;&#x6846;&#x5185;&#x5BB9;&#x6539;&#x53D8;&#x65F6;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF1B;&#x6CE8;&#xFF1A;&#x5185;&#x5BB9;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>controller</code>&#x6765;&#x76D1;&#x542C;&#x3002;</p>
</li>
<li><p><code>onEditingComplete</code>&#x548C;<code>onSubmitted</code>&#xFF1A;&#x8FD9;&#x4E24;&#x4E2A;&#x56DE;&#x8C03;&#x90FD;&#x662F;&#x5728;&#x8F93;&#x5165;&#x6846;&#x8F93;&#x5165;&#x5B8C;&#x6210;&#x65F6;&#x89E6;&#x53D1;&#xFF0C;&#x6BD4;&#x5982;&#x6309;&#x4E86;&#x952E;&#x76D8;&#x7684;&#x5B8C;&#x6210;&#x952E;&#xFF08;&#x5BF9;&#x53F7;&#x56FE;&#x6807;&#xFF09;&#x6216;&#x641C;&#x7D22;&#x952E;&#xFF08;&#x1F50D;&#x56FE;&#x6807;&#xFF09;&#x3002;&#x4E0D;&#x540C;&#x7684;&#x662F;&#x4E24;&#x4E2A;&#x56DE;&#x8C03;&#x7B7E;&#x540D;&#x4E0D;&#x540C;&#xFF0C;<code>onSubmitted</code>&#x56DE;&#x8C03;&#x662F;<code>ValueChanged<span class="token tag"><span class="token tag"><span class="token punctuation">&lt;</span>String</span><span class="token punctuation">&gt;</span></span></code>&#x7C7B;&#x578B;&#xFF0C;&#x5B83;&#x63A5;&#x6536;&#x5F53;&#x524D;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x505A;&#x4E3A;&#x53C2;&#x6570;&#xFF0C;&#x800C;<code>onEditingComplete</code>&#x4E0D;&#x63A5;&#x6536;&#x53C2;&#x6570;&#x3002;</p>
</li>
<li><p><code>inputFormatters</code>&#xFF1A;&#x7528;&#x4E8E;&#x6307;&#x5B9A;&#x8F93;&#x5165;&#x683C;&#x5F0F;&#xFF1B;&#x5F53;&#x7528;&#x6237;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x6539;&#x53D8;&#x65F6;&#xFF0C;&#x4F1A;&#x6839;&#x636E;&#x6307;&#x5B9A;&#x7684;&#x683C;&#x5F0F;&#x6765;&#x6821;&#x9A8C;&#x3002;</p>
</li>
<li><p><code>enable</code>&#xFF1A;&#x5982;&#x679C;&#x4E3A;<code>false</code>&#xFF0C;&#x5219;&#x8F93;&#x5165;&#x6846;&#x4F1A;&#x88AB;&#x7981;&#x7528;&#xFF0C;&#x7981;&#x7528;&#x72B6;&#x6001;&#x4E0D;&#x63A5;&#x6536;&#x8F93;&#x5165;&#x548C;&#x4E8B;&#x4EF6;&#xFF0C;&#x540C;&#x65F6;&#x663E;&#x793A;&#x7981;&#x7528;&#x6001;&#x6837;&#x5F0F;&#xFF08;&#x5728;&#x5176;<code>decoration</code>&#x4E2D;&#x5B9A;&#x4E49;&#xFF09;&#x3002;</p>
</li>
<li><p><code>cursorWidth</code>&#x3001;<code>cursorRadius</code>&#x548C;<code>cursorColor</code>&#xFF1A;&#x8FD9;&#x4E09;&#x4E2A;&#x5C5E;&#x6027;&#x662F;&#x7528;&#x4E8E;&#x81EA;&#x5B9A;&#x4E49;&#x8F93;&#x5165;&#x6846;&#x5149;&#x6807;&#x5BBD;&#x5EA6;&#x3001;&#x5706;&#x89D2;&#x548C;&#x989C;&#x8272;&#x7684;&#x3002;</p>
</li>
</ul>
<h4 id="&#x793A;&#x4F8B;&#xFF1A;&#x767B;&#x5F55;&#x8F93;&#x5165;&#x6846;">&#x793A;&#x4F8B;&#xFF1A;&#x767B;&#x5F55;&#x8F93;&#x5165;&#x6846;</h4>
<h5 id="&#x5E03;&#x5C40;">&#x5E03;&#x5C40;</h5>
<pre class="language-"><code class="lang-dart"><span class="token function">Column</span><span class="token punctuation">(</span>
        children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
          <span class="token function">TextField</span><span class="token punctuation">(</span>
            autofocus<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
            decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&quot;</span><span class="token punctuation">,</span>
                hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&#x6216;&#x90AE;&#x7BB1;&quot;</span><span class="token punctuation">,</span>
                prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>person<span class="token punctuation">)</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token function">TextField</span><span class="token punctuation">(</span>
            decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
                hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x60A8;&#x7684;&#x767B;&#x5F55;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
                prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>lock<span class="token punctuation">)</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
            obscureText<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x540E;&#xFF0C;&#x6548;&#x679C;&#x5982;&#x56FE;3-25&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-25.png" alt="&#x56FE;3-25"></p>
<h5 id="&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x5185;&#x5BB9;">&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x5185;&#x5BB9;</h5>
<p>&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ol>
<li>&#x5B9A;&#x4E49;&#x4E24;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x7528;&#x6237;&#x540D;&#x548C;&#x5BC6;&#x7801;&#xFF0C;&#x7136;&#x540E;&#x5728;<code>onChange</code>&#x89E6;&#x53D1;&#x65F6;&#xFF0C;&#x5404;&#x81EA;&#x4FDD;&#x5B58;&#x4E00;&#x4E0B;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x3002;</li>
<li>&#x901A;&#x8FC7;<code>controller</code>&#x76F4;&#x63A5;&#x83B7;&#x53D6;&#x3002;</li>
</ol>
<p>&#x7B2C;&#x4E00;&#x79CD;&#x65B9;&#x5F0F;&#x6BD4;&#x8F83;&#x7B80;&#x5355;&#xFF0C;&#x4E0D;&#x5728;&#x4E3E;&#x4F8B;&#xFF0C;&#x6211;&#x4EEC;&#x6765;&#x91CD;&#x70B9;&#x770B;&#x4E00;&#x4E0B;&#x7B2C;&#x4E8C;&#x79CD;&#x65B9;&#x5F0F;&#xFF0C;&#x6211;&#x4EEC;&#x4EE5;&#x7528;&#x6237;&#x540D;&#x8F93;&#x5165;&#x6846;&#x4E3E;&#x4F8B;&#xFF1A;</p>
<p>&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;<code>controller</code>&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token comment">//&#x5B9A;&#x4E49;&#x4E00;&#x4E2A;controller</span>
TextEditingController _unameController <span class="token operator">=</span> <span class="token function">TextEditingController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x7136;&#x540E;&#x8BBE;&#x7F6E;&#x8F93;&#x5165;&#x6846;controller&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">TextField</span><span class="token punctuation">(</span>
    autofocus<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    controller<span class="token punctuation">:</span> _unameController<span class="token punctuation">,</span> <span class="token comment">//&#x8BBE;&#x7F6E;controller</span>
    <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x901A;&#x8FC7;controller&#x83B7;&#x53D6;&#x8F93;&#x5165;&#x6846;&#x5185;&#x5BB9;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">print</span><span class="token punctuation">(</span>_unameController<span class="token punctuation">.</span>text<span class="token punctuation">)</span>
</code></pre>
<h5 id="&#x76D1;&#x542C;&#x6587;&#x672C;&#x53D8;&#x5316;">&#x76D1;&#x542C;&#x6587;&#x672C;&#x53D8;&#x5316;</h5>
<p>&#x76D1;&#x542C;&#x6587;&#x672C;&#x53D8;&#x5316;&#x4E5F;&#x6709;&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#xFF1A;</p>
<ol>
<li><p>&#x8BBE;&#x7F6E;<code>onChange</code>&#x56DE;&#x8C03;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">TextField</span><span class="token punctuation">(</span>
    autofocus<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
    onChanged<span class="token punctuation">:</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token function">print</span><span class="token punctuation">(</span><span class="token string">&quot;onChange: $v&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">)</span>
</code></pre>
</li>
<li><p>&#x901A;&#x8FC7;<code>controller</code>&#x76D1;&#x542C;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token metadata symbol">@override</span>
<span class="token keyword">void</span> <span class="token function">initState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token comment">//&#x76D1;&#x542C;&#x8F93;&#x5165;&#x6539;&#x53D8;  </span>
  _unameController<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token function">print</span><span class="token punctuation">(</span>_unameController<span class="token punctuation">.</span>text<span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ol>
<p>&#x4E24;&#x79CD;&#x65B9;&#x5F0F;&#x76F8;&#x6BD4;&#xFF0C;<code>onChanged</code>&#x662F;&#x4E13;&#x95E8;&#x7528;&#x4E8E;&#x76D1;&#x542C;&#x6587;&#x672C;&#x53D8;&#x5316;&#xFF0C;&#x800C;<code>controller</code>&#x7684;&#x529F;&#x80FD;&#x5374;&#x591A;&#x4E00;&#x4E9B;&#xFF0C;&#x9664;&#x4E86;&#x80FD;&#x76D1;&#x542C;&#x6587;&#x672C;&#x53D8;&#x5316;&#x5916;&#xFF0C;&#x5B83;&#x8FD8;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;&#x3001;&#x9009;&#x62E9;&#x6587;&#x672C;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x770B;&#x4E00;&#x4E2A;&#x4F8B;&#x5B50;&#xFF1A;</p>
<p>&#x521B;&#x5EFA;&#x4E00;&#x4E2A;<code>controller</code>:</p>
<pre class="language-"><code class="lang-dart">TextEditingController _selectionController <span class="token operator">=</span>  <span class="token function">TextEditingController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x503C;&#xFF0C;&#x5E76;&#x4ECE;&#x7B2C;&#x4E09;&#x4E2A;&#x5B57;&#x7B26;&#x5F00;&#x59CB;&#x9009;&#x4E2D;&#x540E;&#x9762;&#x7684;&#x5B57;&#x7B26;</p>
<pre class="language-"><code class="lang-dart">_selectionController<span class="token punctuation">.</span>text<span class="token operator">=</span><span class="token string">&quot;hello world!&quot;</span><span class="token punctuation">;</span>
_selectionController<span class="token punctuation">.</span>selection<span class="token operator">=</span><span class="token function">TextSelection</span><span class="token punctuation">(</span>
    baseOffset<span class="token punctuation">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
    extentOffset<span class="token punctuation">:</span> _selectionController<span class="token punctuation">.</span>text<span class="token punctuation">.</span>length
<span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x8BBE;&#x7F6E;<code>controlle</code>r:</p>
<pre class="language-"><code class="lang-dart"><span class="token function">TextField</span><span class="token punctuation">(</span>
  controller<span class="token punctuation">:</span> _selectionController<span class="token punctuation">,</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#x5982;&#x56FE;3-26&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-26.png" alt="&#x56FE;3-26"></p>
<h5 id="&#x63A7;&#x5236;&#x7126;&#x70B9;">&#x63A7;&#x5236;&#x7126;&#x70B9;</h5>
<p>&#x7126;&#x70B9;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>FocusNode</code>&#x548C;<code>FocusScopeNode</code>&#x6765;&#x63A7;&#x5236;&#xFF0C;&#x9ED8;&#x8BA4;&#x60C5;&#x51B5;&#x4E0B;&#xFF0C;&#x7126;&#x70B9;&#x7531;<code>FocusScope</code>&#x6765;&#x7BA1;&#x7406;&#xFF0C;&#x5B83;&#x4EE3;&#x8868;&#x7126;&#x70B9;&#x63A7;&#x5236;&#x8303;&#x56F4;&#xFF0C;&#x53EF;&#x4EE5;&#x5728;&#x8FD9;&#x4E2A;&#x8303;&#x56F4;&#x5185;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>FocusScopeNode</code>&#x5728;&#x8F93;&#x5165;&#x6846;&#x4E4B;&#x95F4;&#x79FB;&#x52A8;&#x7126;&#x70B9;&#x3001;&#x8BBE;&#x7F6E;&#x9ED8;&#x8BA4;&#x7126;&#x70B9;&#x7B49;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>FocusScope.of(context)</code> &#x6765;&#x83B7;&#x53D6;Widget&#x6811;&#x4E2D;&#x9ED8;&#x8BA4;&#x7684;<code>FocusScopeNode</code>&#x3002;&#x4E0B;&#x9762;&#x770B;&#x4E00;&#x4E2A;&#x793A;&#x4F8B;&#xFF0C;&#x5728;&#x6B64;&#x793A;&#x4F8B;&#x4E2D;&#x521B;&#x5EFA;&#x4E24;&#x4E2A;<code>TextField</code>&#xFF0C;&#x7B2C;&#x4E00;&#x4E2A;&#x81EA;&#x52A8;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#xFF0C;&#x7136;&#x540E;&#x521B;&#x5EFA;&#x4E24;&#x4E2A;&#x6309;&#x94AE;&#xFF1A;</p>
<ul>
<li>&#x70B9;&#x51FB;&#x7B2C;&#x4E00;&#x4E2A;&#x6309;&#x94AE;&#x53EF;&#x4EE5;&#x5C06;&#x7126;&#x70B9;&#x4ECE;&#x7B2C;&#x4E00;&#x4E2A;<code>TextField</code>&#x632A;&#x5230;&#x7B2C;&#x4E8C;&#x4E2A;<code>TextField</code>&#x3002;</li>
<li>&#x70B9;&#x51FB;&#x7B2C;&#x4E8C;&#x4E2A;&#x6309;&#x94AE;&#x53EF;&#x4EE5;&#x5173;&#x95ED;&#x952E;&#x76D8;&#x3002;</li>
</ul>
<p>&#x6211;&#x4EEC;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x6548;&#x679C;&#x5982;&#x56FE;3-27&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-27.png" alt="&#x56FE;3-27"></p>
<p>&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">FocusTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _FocusTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">new</span> <span class="token class-name">_FocusTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_FocusTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>FocusTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  FocusNode focusNode1 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FocusNode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  FocusNode focusNode2 <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FocusNode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  FocusScopeNode focusScopeNode<span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Padding</span><span class="token punctuation">(</span>
      padding<span class="token punctuation">:</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token number">16.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
        children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
          <span class="token function">TextField</span><span class="token punctuation">(</span>
            autofocus<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> 
            focusNode<span class="token punctuation">:</span> focusNode1<span class="token punctuation">,</span><span class="token comment">//&#x5173;&#x8054;focusNode1</span>
            decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                labelText<span class="token punctuation">:</span> <span class="token string">&quot;input1&quot;</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token function">TextField</span><span class="token punctuation">(</span>
            focusNode<span class="token punctuation">:</span> focusNode2<span class="token punctuation">,</span><span class="token comment">//&#x5173;&#x8054;focusNode2</span>
            decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                labelText<span class="token punctuation">:</span> <span class="token string">&quot;input2&quot;</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token function">Builder</span><span class="token punctuation">(</span>builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">return</span> <span class="token function">Column</span><span class="token punctuation">(</span>
              children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                <span class="token function">RaisedButton</span><span class="token punctuation">(</span>
                  child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;&#x79FB;&#x52A8;&#x7126;&#x70B9;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                  onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">//&#x5C06;&#x7126;&#x70B9;&#x4ECE;&#x7B2C;&#x4E00;&#x4E2A;TextField&#x79FB;&#x5230;&#x7B2C;&#x4E8C;&#x4E2A;TextField</span>
                    <span class="token comment">// &#x8FD9;&#x662F;&#x4E00;&#x79CD;&#x5199;&#x6CD5; FocusScope.of(context).requestFocus(focusNode2);</span>
                    <span class="token comment">// &#x8FD9;&#x662F;&#x7B2C;&#x4E8C;&#x79CD;&#x5199;&#x6CD5;</span>
                    <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token keyword">null</span> <span class="token operator">==</span> focusScopeNode<span class="token punctuation">)</span><span class="token punctuation">{</span>
                      focusScopeNode <span class="token operator">=</span> FocusScope<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span>
                    <span class="token punctuation">}</span>
                    focusScopeNode<span class="token punctuation">.</span><span class="token function">requestFocus</span><span class="token punctuation">(</span>focusNode2<span class="token punctuation">)</span><span class="token punctuation">;</span>
                  <span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token function">RaisedButton</span><span class="token punctuation">(</span>
                  child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;&#x9690;&#x85CF;&#x952E;&#x76D8;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                  onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">// &#x5F53;&#x6240;&#x6709;&#x7F16;&#x8F91;&#x6846;&#x90FD;&#x5931;&#x53BB;&#x7126;&#x70B9;&#x65F6;&#x952E;&#x76D8;&#x5C31;&#x4F1A;&#x6536;&#x8D77;  </span>
                    focusNode1<span class="token punctuation">.</span><span class="token function">unfocus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                    focusNode2<span class="token punctuation">.</span><span class="token function">unfocus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                  <span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">]</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

<span class="token punctuation">}</span>
</code></pre>
<p><code>FocusNode</code>&#x548C;<code>FocusScopeNode</code>&#x8FD8;&#x6709;&#x4E00;&#x4E9B;&#x5176;&#x5B83;&#x7684;&#x65B9;&#x6CD5;&#xFF0C;&#x8BE6;&#x60C5;&#x53EF;&#x4EE5;&#x67E5;&#x770B;API&#x6587;&#x6863;&#x3002;</p>
<h5 id="&#x76D1;&#x542C;&#x7126;&#x70B9;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;">&#x76D1;&#x542C;&#x7126;&#x70B9;&#x72B6;&#x6001;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;</h5>
<p><code>FocusNode</code>&#x7EE7;&#x627F;&#x81EA;<code>ChangeNotifier</code>&#xFF0C;&#x901A;&#x8FC7;<code>FocusNode</code>&#x53EF;&#x4EE5;&#x76D1;&#x542C;&#x7126;&#x70B9;&#x7684;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;&#xFF0C;&#x5982;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token comment">// &#x521B;&#x5EFA; focusNode   </span>
FocusNode focusNode <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">FocusNode</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token comment">// focusNode&#x7ED1;&#x5B9A;&#x8F93;&#x5165;&#x6846;   </span>
<span class="token function">TextField</span><span class="token punctuation">(</span>focusNode<span class="token punctuation">:</span> focusNode<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
<span class="token comment">// &#x76D1;&#x542C;&#x7126;&#x70B9;&#x53D8;&#x5316;    </span>
focusNode<span class="token punctuation">.</span><span class="token function">addListener</span><span class="token punctuation">(</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
   <span class="token function">print</span><span class="token punctuation">(</span>focusNode<span class="token punctuation">.</span>hasFocus<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x83B7;&#x5F97;&#x7126;&#x70B9;&#x65F6;<code>focusNode.hasFocus</code>&#x503C;&#x4E3A;<code>true</code>&#xFF0C;&#x5931;&#x53BB;&#x7126;&#x70B9;&#x65F6;&#x4E3A;<code>false</code>&#x3002;</p>
<h5 id="&#x81EA;&#x5B9A;&#x4E49;&#x6837;&#x5F0F;">&#x81EA;&#x5B9A;&#x4E49;&#x6837;&#x5F0F;</h5>
<p>&#x867D;&#x7136;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>decoration</code>&#x5C5E;&#x6027;&#x6765;&#x5B9A;&#x4E49;&#x8F93;&#x5165;&#x6846;&#x6837;&#x5F0F;&#xFF0C;&#x4E0B;&#x9762;&#x4EE5;&#x81EA;&#x5B9A;&#x4E49;&#x8F93;&#x5165;&#x6846;&#x4E0B;&#x5212;&#x7EBF;&#x989C;&#x8272;&#x4E3A;&#x4F8B;&#x6765;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">TextField</span><span class="token punctuation">(</span>
  decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
    labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x8BF7;&#x8F93;&#x5165;&#x7528;&#x6237;&#x540D;&quot;</span><span class="token punctuation">,</span>
    prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>person<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token comment">// &#x672A;&#x83B7;&#x5F97;&#x7126;&#x70B9;&#x4E0B;&#x5212;&#x7EBF;&#x8BBE;&#x4E3A;&#x7070;&#x8272;</span>
    enabledBorder<span class="token punctuation">:</span> <span class="token function">UnderlineInputBorder</span><span class="token punctuation">(</span>
      borderSide<span class="token punctuation">:</span> <span class="token function">BorderSide</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token comment">//&#x83B7;&#x5F97;&#x7126;&#x70B9;&#x4E0B;&#x5212;&#x7EBF;&#x8BBE;&#x4E3A;&#x84DD;&#x8272;</span>
    focusedBorder<span class="token punctuation">:</span> <span class="token function">UnderlineInputBorder</span><span class="token punctuation">(</span>
      borderSide<span class="token punctuation">:</span> <span class="token function">BorderSide</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>blue<span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">)</span><span class="token punctuation">,</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x901A;&#x8FC7;InputDecoration&#x7684;enabledBorder&#x548C;focusedBorder&#x6765;&#x5206;&#x522B;&#x8BBE;&#x7F6E;&#x4E86;&#x8F93;&#x5165;&#x6846;&#x5728;&#x672A;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#x548C;&#x83B7;&#x5F97;&#x7126;&#x70B9;&#x540E;&#x7684;&#x4E0B;&#x5212;&#x7EBF;&#x989C;&#x8272;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x4E5F;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E3B;&#x9898;&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#x8F93;&#x5165;&#x6846;&#x7684;&#x6837;&#x5F0F;&#xFF0C;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x63A2;&#x7D22;&#x4E00;&#x4E0B;&#x5982;&#x4F55;&#x5728;&#x4E0D;&#x4F7F;&#x7528;enabledBorder&#x548C;focusedBorder&#x7684;&#x60C5;&#x51B5;&#x4E0B;&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#x4E0B;&#x6ED1;&#x7EBF;&#x989C;&#x8272;&#x3002;</p>
<p>&#x7531;&#x4E8E;<code>TextField</code>&#x5728;&#x7ED8;&#x5236;&#x4E0B;&#x5212;&#x7EBF;&#x65F6;&#x4F7F;&#x7528;&#x7684;&#x989C;&#x8272;&#x662F;&#x4E3B;&#x9898;&#x8272;&#x91CC;&#x9762;&#x7684;<code>hintColor</code>&#xFF0C;&#x4F46;&#x63D0;&#x793A;&#x6587;&#x672C;&#x989C;&#x8272;&#x4E5F;&#x662F;&#x7528;&#x7684;<code>hintColor</code>&#xFF0C; &#x5982;&#x679C;&#x6211;&#x4EEC;&#x76F4;&#x63A5;&#x4FEE;&#x6539;<code>hintColor</code>&#xFF0C;&#x90A3;&#x4E48;&#x4E0B;&#x5212;&#x7EBF;&#x548C;&#x63D0;&#x793A;&#x6587;&#x672C;&#x7684;&#x989C;&#x8272;&#x90FD;&#x4F1A;&#x53D8;&#x3002;&#x503C;&#x5F97;&#x9AD8;&#x5174;&#x7684;&#x662F;<code>decoration</code>&#x4E2D;&#x53EF;&#x4EE5;&#x8BBE;&#x7F6E;<code>hintStyle</code>&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x8986;&#x76D6;<code>hintColor</code>&#xFF0C;&#x5E76;&#x4E14;&#x4E3B;&#x9898;&#x4E2D;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>inputDecorationTheme</code>&#x6765;&#x8BBE;&#x7F6E;&#x8F93;&#x5165;&#x6846;&#x9ED8;&#x8BA4;&#x7684;<code>decoration</code>&#x3002;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E3B;&#x9898;&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#xFF0C;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">Theme</span><span class="token punctuation">(</span>
  data<span class="token punctuation">:</span> Theme<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">copyWith</span><span class="token punctuation">(</span>
      hintColor<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">[</span><span class="token number">200</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token comment">//&#x5B9A;&#x4E49;&#x4E0B;&#x5212;&#x7EBF;&#x989C;&#x8272;</span>
      inputDecorationTheme<span class="token punctuation">:</span> <span class="token function">InputDecorationTheme</span><span class="token punctuation">(</span>
          labelStyle<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">)</span><span class="token punctuation">,</span><span class="token comment">//&#x5B9A;&#x4E49;label&#x5B57;&#x4F53;&#x6837;&#x5F0F;</span>
          hintStyle<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">,</span> fontSize<span class="token punctuation">:</span> <span class="token number">14.0</span><span class="token punctuation">)</span><span class="token comment">//&#x5B9A;&#x4E49;&#x63D0;&#x793A;&#x6587;&#x672C;&#x6837;&#x5F0F;</span>
      <span class="token punctuation">)</span>
  <span class="token punctuation">)</span><span class="token punctuation">,</span>
  child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
    children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
      <span class="token function">TextField</span><span class="token punctuation">(</span>
        decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
            labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&quot;</span><span class="token punctuation">,</span>
            hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&#x6216;&#x90AE;&#x7BB1;&quot;</span><span class="token punctuation">,</span>
            prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>person<span class="token punctuation">)</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token function">TextField</span><span class="token punctuation">(</span>
        decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
            prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>lock<span class="token punctuation">)</span><span class="token punctuation">,</span>
            labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
            hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x60A8;&#x7684;&#x767B;&#x5F55;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
            hintStyle<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">,</span> fontSize<span class="token punctuation">:</span> <span class="token number">13.0</span><span class="token punctuation">)</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
        obscureText<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span>
    <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#x5982;&#x56FE;3-28&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-28.png" alt="&#x56FE;3-28"></p>
<p>&#x6211;&#x4EEC;&#x6210;&#x529F;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x4E86;&#x4E0B;&#x5212;&#x7EBF;&#x989C;&#x8272;&#x548C;&#x63D0;&#x95EE;&#x6587;&#x5B57;&#x6837;&#x5F0F;&#xFF0C;&#x7EC6;&#x5FC3;&#x7684;&#x8BFB;&#x8005;&#x53EF;&#x80FD;&#x5DF2;&#x7ECF;&#x53D1;&#x73B0;&#xFF0C;&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x65B9;&#x5F0F;&#x81EA;&#x5B9A;&#x4E49;&#x540E;&#xFF0C;&#x8F93;&#x5165;&#x6846;&#x5728;&#x83B7;&#x53D6;&#x7126;&#x70B9;&#x65F6;&#xFF0C;<code>labelText</code>&#x4E0D;&#x4F1A;&#x9AD8;&#x4EAE;&#x663E;&#x793A;&#x4E86;&#xFF0C;&#x6B63;&#x5982;&#x4E0A;&#x56FE;&#x4E2D;&#x7684;&quot;&#x7528;&#x6237;&#x540D;&quot;&#x672C;&#x5E94;&#x8BE5;&#x663E;&#x793A;&#x84DD;&#x8272;&#xFF0C;&#x4F46;&#x73B0;&#x5728;&#x5374;&#x663E;&#x793A;&#x4E3A;&#x7070;&#x8272;&#xFF0C;&#x5E76;&#x4E14;&#x6211;&#x4EEC;&#x8FD8;&#x662F;&#x65E0;&#x6CD5;&#x5B9A;&#x4E49;&#x4E0B;&#x5212;&#x7EBF;&#x5BBD;&#x5EA6;&#x3002;&#x53E6;&#x4E00;&#x79CD;&#x7075;&#x6D3B;&#x7684;&#x65B9;&#x5F0F;&#x662F;&#x76F4;&#x63A5;&#x9690;&#x85CF;&#x6389;<code>TextField</code>&#x672C;&#x8EAB;&#x7684;&#x4E0B;&#x5212;&#x7EBF;&#xFF0C;&#x7136;&#x540E;&#x901A;&#x8FC7;<code>Container</code>&#x53BB;&#x5D4C;&#x5957;&#x5B9A;&#x4E49;&#x6837;&#x5F0F;&#xFF0C;&#x5982;:</p>
<pre class="language-"><code class="lang-dart"><span class="token function">Container</span><span class="token punctuation">(</span>
  child<span class="token punctuation">:</span> <span class="token function">TextField</span><span class="token punctuation">(</span>
    keyboardType<span class="token punctuation">:</span> TextInputType<span class="token punctuation">.</span>emailAddress<span class="token punctuation">,</span>
    decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
        labelText<span class="token punctuation">:</span> <span class="token string">&quot;Email&quot;</span><span class="token punctuation">,</span>
        hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7535;&#x5B50;&#x90AE;&#x4EF6;&#x5730;&#x5740;&quot;</span><span class="token punctuation">,</span>
        prefixIcon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>email<span class="token punctuation">)</span><span class="token punctuation">,</span>
        border<span class="token punctuation">:</span> InputBorder<span class="token punctuation">.</span>none <span class="token comment">//&#x9690;&#x85CF;&#x4E0B;&#x5212;&#x7EBF;</span>
    <span class="token punctuation">)</span>
  <span class="token punctuation">)</span><span class="token punctuation">,</span>
  decoration<span class="token punctuation">:</span> <span class="token function">BoxDecoration</span><span class="token punctuation">(</span>
      <span class="token comment">// &#x4E0B;&#x6ED1;&#x7EBF;&#x6D45;&#x7070;&#x8272;&#xFF0C;&#x5BBD;&#x5EA6;1&#x50CF;&#x7D20;</span>
      border<span class="token punctuation">:</span> <span class="token function">Border</span><span class="token punctuation">(</span>bottom<span class="token punctuation">:</span> <span class="token function">BorderSide</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">[</span><span class="token number">200</span><span class="token punctuation">]</span><span class="token punctuation">,</span> width<span class="token punctuation">:</span> <span class="token number">1.0</span><span class="token punctuation">)</span><span class="token punctuation">)</span>
  <span class="token punctuation">)</span><span class="token punctuation">,</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x6548;&#x679C;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0/docs/imgs/image-20180904150511545.png" alt="image-20180904150511545"></p>
<p>&#x901A;&#x8FC7;&#x8FD9;&#x79CD;&#x7EC4;&#x4EF6;&#x7EC4;&#x5408;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5B9A;&#x4E49;&#x80CC;&#x666F;&#x5706;&#x89D2;&#x7B49;&#x3002;&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;&#x4F18;&#x5148;&#x901A;&#x8FC7;<code>decoration</code>&#x6765;&#x81EA;&#x5B9A;&#x4E49;&#x6837;&#x5F0F;&#xFF0C;&#x5982;&#x679C;<code>decoration</code>&#x5B9E;&#x73B0;&#x4E0D;&#x4E86;&#xFF0C;&#x518D;&#x7528;widget&#x7EC4;&#x5408;&#x7684;&#x65B9;&#x5F0F;&#x3002;</p>
<blockquote>
<p>&#x601D;&#x8003;&#x9898;&#xFF1A;&#x5728;&#x8FD9;&#x4E2A;&#x793A;&#x4F8B;&#x4E2D;&#xFF0C;&#x4E0B;&#x5212;&#x7EBF;&#x989C;&#x8272;&#x662F;&#x56FA;&#x5B9A;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x83B7;&#x5F97;&#x7126;&#x70B9;&#x540E;&#x989C;&#x8272;&#x4ECD;&#x7136;&#x4E3A;&#x7070;&#x8272;&#xFF0C;&#x5982;&#x4F55;&#x5B9E;&#x73B0;&#x70B9;&#x51FB;&#x540E;&#x4E0B;&#x6ED1;&#x7EBF;&#x4E5F;&#x53D8;&#x8272;&#x5462;&#xFF1F;</p>
</blockquote>
<h2 id="372-&#x8868;&#x5355;form">3.7.2 &#x8868;&#x5355;Form</h2>
<p>&#x5B9E;&#x9645;&#x4E1A;&#x52A1;&#x4E2D;&#xFF0C;&#x5728;&#x6B63;&#x5F0F;&#x5411;&#x670D;&#x52A1;&#x5668;&#x63D0;&#x4EA4;&#x6570;&#x636E;&#x524D;&#xFF0C;&#x90FD;&#x4F1A;&#x5BF9;&#x5404;&#x4E2A;&#x8F93;&#x5165;&#x6846;&#x6570;&#x636E;&#x8FDB;&#x884C;&#x5408;&#x6CD5;&#x6027;&#x6821;&#x9A8C;&#xFF0C;&#x4F46;&#x662F;&#x5BF9;&#x6BCF;&#x4E00;&#x4E2A;<code>TextField</code>&#x90FD;&#x5206;&#x522B;&#x8FDB;&#x884C;&#x6821;&#x9A8C;&#x5C06;&#x4F1A;&#x662F;&#x4E00;&#x4EF6;&#x5F88;&#x9EBB;&#x70E6;&#x7684;&#x4E8B;&#x3002;&#x8FD8;&#x6709;&#xFF0C;&#x5982;&#x679C;&#x7528;&#x6237;&#x60F3;&#x6E05;&#x9664;&#x4E00;&#x7EC4;<code>TextField</code>&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x9664;&#x4E86;&#x4E00;&#x4E2A;&#x4E00;&#x4E2A;&#x6E05;&#x9664;&#x6709;&#x6CA1;&#x6709;&#x4EC0;&#x4E48;&#x66F4;&#x597D;&#x7684;&#x529E;&#x6CD5;&#x5462;&#xFF1F;&#x4E3A;&#x6B64;&#xFF0C;Flutter&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;<code>Form</code> &#x7EC4;&#x4EF6;&#xFF0C;&#x5B83;&#x53EF;&#x4EE5;&#x5BF9;&#x8F93;&#x5165;&#x6846;&#x8FDB;&#x884C;&#x5206;&#x7EC4;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x7EDF;&#x4E00;&#x64CD;&#x4F5C;&#xFF0C;&#x5982;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x6821;&#x9A8C;&#x3001;&#x8F93;&#x5165;&#x6846;&#x91CD;&#x7F6E;&#x4EE5;&#x53CA;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#x4FDD;&#x5B58;&#x3002;</p>
<h4 id="form">Form</h4>
<p><code>Form</code>&#x7EE7;&#x627F;&#x81EA;<code>StatefulWidget</code>&#x5BF9;&#x8C61;&#xFF0C;&#x5B83;&#x5BF9;&#x5E94;&#x7684;&#x72B6;&#x6001;&#x7C7B;&#x4E3A;<code>FormState</code>&#x3002;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x770B;<code>Form</code>&#x7C7B;&#x7684;&#x5B9A;&#x4E49;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">Form</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token metadata symbol">@required</span> Widget child<span class="token punctuation">,</span>
  bool autovalidate <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span>
  WillPopCallback onWillPop<span class="token punctuation">,</span>
  VoidCallback onChanged<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<ul>
<li><code>autovalidate</code>&#xFF1A;&#x662F;&#x5426;&#x81EA;&#x52A8;&#x6821;&#x9A8C;&#x8F93;&#x5165;&#x5185;&#x5BB9;&#xFF1B;&#x5F53;&#x4E3A;<code>true</code>&#x65F6;&#xFF0C;&#x6BCF;&#x4E00;&#x4E2A;&#x5B50;FormField&#x5185;&#x5BB9;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x90FD;&#x4F1A;&#x81EA;&#x52A8;&#x6821;&#x9A8C;&#x5408;&#x6CD5;&#x6027;&#xFF0C;&#x5E76;&#x76F4;&#x63A5;&#x663E;&#x793A;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x3002;&#x5426;&#x5219;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x8C03;&#x7528;<code>FormState.validate()</code>&#x6765;&#x624B;&#x52A8;&#x6821;&#x9A8C;&#x3002;</li>
<li><code>onWillPop</code>&#xFF1A;&#x51B3;&#x5B9A;<code>Form</code>&#x6240;&#x5728;&#x7684;&#x8DEF;&#x7531;&#x662F;&#x5426;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x8FD4;&#x56DE;&#xFF08;&#x5982;&#x70B9;&#x51FB;&#x8FD4;&#x56DE;&#x6309;&#x94AE;&#xFF09;&#xFF0C;&#x8BE5;&#x56DE;&#x8C03;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;<code>Future</code>&#x5BF9;&#x8C61;&#xFF0C;&#x5982;&#x679C;Future&#x7684;&#x6700;&#x7EC8;&#x7ED3;&#x679C;&#x662F;<code>false</code>&#xFF0C;&#x5219;&#x5F53;&#x524D;&#x8DEF;&#x7531;&#x4E0D;&#x4F1A;&#x8FD4;&#x56DE;&#xFF1B;&#x5982;&#x679C;&#x4E3A;<code>true</code>&#xFF0C;&#x5219;&#x4F1A;&#x8FD4;&#x56DE;&#x5230;&#x4E0A;&#x4E00;&#x4E2A;&#x8DEF;&#x7531;&#x3002;&#x6B64;&#x5C5E;&#x6027;&#x901A;&#x5E38;&#x7528;&#x4E8E;&#x62E6;&#x622A;&#x8FD4;&#x56DE;&#x6309;&#x94AE;&#x3002;</li>
<li><code>onChanged</code>&#xFF1A;<code>Form</code>&#x7684;&#x4EFB;&#x610F;&#x4E00;&#x4E2A;&#x5B50;<code>FormField</code>&#x5185;&#x5BB9;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x65F6;&#x4F1A;&#x89E6;&#x53D1;&#x6B64;&#x56DE;&#x8C03;&#x3002;</li>
</ul>
<h4 id="formfield">FormField</h4>
<p><code>Form</code>&#x7684;&#x5B50;&#x5B59;&#x5143;&#x7D20;&#x5FC5;&#x987B;&#x662F;<code>FormField</code>&#x7C7B;&#x578B;&#xFF0C;<code>FormField</code>&#x662F;&#x4E00;&#x4E2A;&#x62BD;&#x8C61;&#x7C7B;&#xFF0C;&#x5B9A;&#x4E49;&#x51E0;&#x4E2A;&#x5C5E;&#x6027;&#xFF0C;<code>FormState</code>&#x5185;&#x90E8;&#x901A;&#x8FC7;&#x5B83;&#x4EEC;&#x6765;&#x5B8C;&#x6210;&#x64CD;&#x4F5C;&#xFF0C;<code>FormField</code>&#x90E8;&#x5206;&#x5B9A;&#x4E49;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">const</span> <span class="token function">FormField</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
  FormFieldSetter<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span> onSaved<span class="token punctuation">,</span> <span class="token comment">//&#x4FDD;&#x5B58;&#x56DE;&#x8C03;</span>
  FormFieldValidator<span class="token operator">&lt;</span>T<span class="token operator">&gt;</span>  validator<span class="token punctuation">,</span> <span class="token comment">//&#x9A8C;&#x8BC1;&#x56DE;&#x8C03;</span>
  T initialValue<span class="token punctuation">,</span> <span class="token comment">//&#x521D;&#x59CB;&#x503C;</span>
  bool autovalidate <span class="token operator">=</span> <span class="token boolean">false</span><span class="token punctuation">,</span> <span class="token comment">//&#x662F;&#x5426;&#x81EA;&#x52A8;&#x6821;&#x9A8C;&#x3002;</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre>
<p>&#x4E3A;&#x4E86;&#x65B9;&#x4FBF;&#x4F7F;&#x7528;&#xFF0C;Flutter&#x63D0;&#x4F9B;&#x4E86;&#x4E00;&#x4E2A;<code>TextFormField</code>&#x7EC4;&#x4EF6;&#xFF0C;&#x5B83;&#x7EE7;&#x627F;&#x81EA;<code>FormField</code>&#x7C7B;&#xFF0C;&#x4E5F;&#x662F;<code>TextField</code>&#x7684;&#x4E00;&#x4E2A;&#x5305;&#x88C5;&#x7C7B;&#xFF0C;&#x6240;&#x4EE5;&#x9664;&#x4E86;<code>FormField</code>&#x5B9A;&#x4E49;&#x7684;&#x5C5E;&#x6027;&#x4E4B;&#x5916;&#xFF0C;&#x5B83;&#x8FD8;&#x5305;&#x62EC;<code>TextField</code>&#x7684;&#x5C5E;&#x6027;&#x3002;</p>
<h4 id="formstate">FormState</h4>
<p><code>FormState</code>&#x4E3A;<code>Form</code>&#x7684;<code>State</code>&#x7C7B;&#xFF0C;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>Form.of()</code>&#x6216;<code>GlobalKey</code>&#x83B7;&#x5F97;&#x3002;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x5B83;&#x6765;&#x5BF9;<code>Form</code>&#x7684;&#x5B50;&#x5B59;<code>FormField</code>&#x8FDB;&#x884C;&#x7EDF;&#x4E00;&#x64CD;&#x4F5C;&#x3002;&#x6211;&#x4EEC;&#x770B;&#x770B;&#x5176;&#x5E38;&#x7528;&#x7684;&#x4E09;&#x4E2A;&#x65B9;&#x6CD5;&#xFF1A;</p>
<ul>
<li><code>FormState.validate()</code>&#xFF1A;&#x8C03;&#x7528;&#x6B64;&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>Form</code>&#x5B50;&#x5B59;<code>FormField&#x7684;validate</code>&#x56DE;&#x8C03;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x4E00;&#x4E2A;&#x6821;&#x9A8C;&#x5931;&#x8D25;&#xFF0C;&#x5219;&#x8FD4;&#x56DE;false&#xFF0C;&#x6240;&#x6709;&#x6821;&#x9A8C;&#x5931;&#x8D25;&#x9879;&#x90FD;&#x4F1A;&#x8FD4;&#x56DE;&#x7528;&#x6237;&#x8FD4;&#x56DE;&#x7684;&#x9519;&#x8BEF;&#x63D0;&#x793A;&#x3002;</li>
<li><code>FormState.save()</code>&#xFF1A;&#x8C03;&#x7528;&#x6B64;&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x4F1A;&#x8C03;&#x7528;<code>Form</code>&#x5B50;&#x5B59;<code>FormField</code>&#x7684;<code>save</code>&#x56DE;&#x8C03;&#xFF0C;&#x7528;&#x4E8E;&#x4FDD;&#x5B58;&#x8868;&#x5355;&#x5185;&#x5BB9;</li>
<li><code>FormState.reset()</code>&#xFF1A;&#x8C03;&#x7528;&#x6B64;&#x65B9;&#x6CD5;&#x540E;&#xFF0C;&#x4F1A;&#x5C06;&#x5B50;&#x5B59;<code>FormField</code>&#x7684;&#x5185;&#x5BB9;&#x6E05;&#x7A7A;&#x3002;</li>
</ul>
<h4 id="&#x793A;&#x4F8B;">&#x793A;&#x4F8B;</h4>
<p>&#x6211;&#x4EEC;&#x4FEE;&#x6539;&#x4E00;&#x4E0B;&#x4E0A;&#x9762;&#x7528;&#x6237;&#x767B;&#x5F55;&#x7684;&#x793A;&#x4F8B;&#xFF0C;&#x5728;&#x63D0;&#x4EA4;&#x4E4B;&#x524D;&#x6821;&#x9A8C;&#xFF1A;</p>
<ol>
<li>&#x7528;&#x6237;&#x540D;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&#xFF0C;&#x5982;&#x679C;&#x4E3A;&#x7A7A;&#x5219;&#x63D0;&#x793A;&#x201C;&#x7528;&#x6237;&#x540D;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&#x201D;&#x3002;</li>
<li>&#x5BC6;&#x7801;&#x4E0D;&#x80FD;&#x5C0F;&#x4E8E;6&#x4F4D;&#xFF0C;&#x5982;&#x679C;&#x5C0F;&#x4E8E;6&#x4E3A;&#x5219;&#x63D0;&#x793A;&#x201C;&#x5BC6;&#x7801;&#x4E0D;&#x80FD;&#x5C11;&#x4E8E;6&#x4F4D;&#x201D;&#x3002;</li>
</ol>
<p>&#x5B8C;&#x6574;&#x4EE3;&#x7801;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">FormTestRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _FormTestRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token keyword">new</span> <span class="token class-name">_FormTestRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_FormTestRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>FormTestRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  TextEditingController _unameController <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TextEditingController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  TextEditingController _pwdController <span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">TextEditingController</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
  GlobalKey _formKey<span class="token operator">=</span> <span class="token keyword">new</span> <span class="token class-name">GlobalKey</span><span class="token operator">&lt;</span>FormState<span class="token operator">&gt;</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Scaffold</span><span class="token punctuation">(</span>
      appBar<span class="token punctuation">:</span> <span class="token function">AppBar</span><span class="token punctuation">(</span>
        title<span class="token punctuation">:</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;Form Test&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
      body<span class="token punctuation">:</span> <span class="token function">Padding</span><span class="token punctuation">(</span>
        padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">symmetric</span><span class="token punctuation">(</span>vertical<span class="token punctuation">:</span> <span class="token number">16.0</span><span class="token punctuation">,</span> horizontal<span class="token punctuation">:</span> <span class="token number">24.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        child<span class="token punctuation">:</span> <span class="token function">Form</span><span class="token punctuation">(</span>
          key<span class="token punctuation">:</span> _formKey<span class="token punctuation">,</span> <span class="token comment">//&#x8BBE;&#x7F6E;globalKey&#xFF0C;&#x7528;&#x4E8E;&#x540E;&#x9762;&#x83B7;&#x53D6;FormState</span>
          autovalidate<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span> <span class="token comment">//&#x5F00;&#x542F;&#x81EA;&#x52A8;&#x6821;&#x9A8C;</span>
          child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
            children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
              <span class="token function">TextFormField</span><span class="token punctuation">(</span>
                  autofocus<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
                  controller<span class="token punctuation">:</span> _unameController<span class="token punctuation">,</span>
                  decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                      labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&quot;</span><span class="token punctuation">,</span>
                      hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&#x6216;&#x90AE;&#x7BB1;&quot;</span><span class="token punctuation">,</span>
                      icon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>person<span class="token punctuation">)</span>
                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  <span class="token comment">// &#x6821;&#x9A8C;&#x7528;&#x6237;&#x540D;</span>
                  validator<span class="token punctuation">:</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token keyword">return</span> v
                        <span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                        <span class="token punctuation">.</span>length <span class="token operator">&gt;</span> <span class="token number">0</span> <span class="token operator">?</span> <span class="token keyword">null</span> <span class="token punctuation">:</span> <span class="token string">&quot;&#x7528;&#x6237;&#x540D;&#x4E0D;&#x80FD;&#x4E3A;&#x7A7A;&quot;</span><span class="token punctuation">;</span>
                  <span class="token punctuation">}</span>

              <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token function">TextFormField</span><span class="token punctuation">(</span>
                  controller<span class="token punctuation">:</span> _pwdController<span class="token punctuation">,</span>
                  decoration<span class="token punctuation">:</span> <span class="token function">InputDecoration</span><span class="token punctuation">(</span>
                      labelText<span class="token punctuation">:</span> <span class="token string">&quot;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
                      hintText<span class="token punctuation">:</span> <span class="token string">&quot;&#x60A8;&#x7684;&#x767B;&#x5F55;&#x5BC6;&#x7801;&quot;</span><span class="token punctuation">,</span>
                      icon<span class="token punctuation">:</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>lock<span class="token punctuation">)</span>
                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  obscureText<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
                  <span class="token comment">//&#x6821;&#x9A8C;&#x5BC6;&#x7801;</span>
                  validator<span class="token punctuation">:</span> <span class="token punctuation">(</span>v<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token keyword">return</span> v
                        <span class="token punctuation">.</span><span class="token function">trim</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                        <span class="token punctuation">.</span>length <span class="token operator">&gt;</span> <span class="token number">5</span> <span class="token operator">?</span> <span class="token keyword">null</span> <span class="token punctuation">:</span> <span class="token string">&quot;&#x5BC6;&#x7801;&#x4E0D;&#x80FD;&#x5C11;&#x4E8E;6&#x4F4D;&quot;</span><span class="token punctuation">;</span>
                  <span class="token punctuation">}</span>
              <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token comment">// &#x767B;&#x5F55;&#x6309;&#x94AE;</span>
              <span class="token function">Padding</span><span class="token punctuation">(</span>
                padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">only</span><span class="token punctuation">(</span>top<span class="token punctuation">:</span> <span class="token number">28.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                child<span class="token punctuation">:</span> <span class="token function">Row</span><span class="token punctuation">(</span>
                  children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                    <span class="token function">Expanded</span><span class="token punctuation">(</span>
                      child<span class="token punctuation">:</span> <span class="token function">RaisedButton</span><span class="token punctuation">(</span>
                        padding<span class="token punctuation">:</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">all</span><span class="token punctuation">(</span><span class="token number">15.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                        child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;&#x767B;&#x5F55;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                        color<span class="token punctuation">:</span> Theme
                            <span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span>
                            <span class="token punctuation">.</span>primaryColor<span class="token punctuation">,</span>
                        textColor<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>white<span class="token punctuation">,</span>
                        onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                          <span class="token comment">//&#x5728;&#x8FD9;&#x91CC;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;&#x6B64;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;FormState&#xFF0C;context&#x4E0D;&#x5BF9;</span>
                          <span class="token comment">//print(Form.of(context));</span>

                          <span class="token comment">// &#x901A;&#x8FC7;_formKey.currentState &#x83B7;&#x53D6;FormState&#x540E;&#xFF0C;</span>
                          <span class="token comment">// &#x8C03;&#x7528;validate()&#x65B9;&#x6CD5;&#x6821;&#x9A8C;&#x7528;&#x6237;&#x540D;&#x5BC6;&#x7801;&#x662F;&#x5426;&#x5408;&#x6CD5;&#xFF0C;&#x6821;&#x9A8C;</span>
                          <span class="token comment">// &#x901A;&#x8FC7;&#x540E;&#x518D;&#x63D0;&#x4EA4;&#x6570;&#x636E;&#x3002; </span>
                          <span class="token keyword">if</span><span class="token punctuation">(</span><span class="token punctuation">(</span>_formKey<span class="token punctuation">.</span>currentState <span class="token operator">as</span> FormState<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
                            <span class="token comment">//&#x9A8C;&#x8BC1;&#x901A;&#x8FC7;&#x63D0;&#x4EA4;&#x6570;&#x636E;</span>
                          <span class="token punctuation">}</span>
                        <span class="token punctuation">}</span><span class="token punctuation">,</span>
                      <span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  <span class="token punctuation">]</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token punctuation">)</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x8FD0;&#x884C;&#x540E;&#x6548;&#x679C;&#x5982;&#x56FE;3-29&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://pcdn.flutterchina.club/imgs/3-29.png" alt="&#x56FE;3-29"></p>
<p>&#x6CE8;&#x610F;&#xFF0C;&#x767B;&#x5F55;&#x6309;&#x94AE;&#x7684;<code>onPressed</code>&#x65B9;&#x6CD5;&#x4E2D;&#x4E0D;&#x80FD;&#x901A;&#x8FC7;<code>Form.of(context)</code>&#x6765;&#x83B7;&#x53D6;&#xFF0C;&#x539F;&#x56E0;&#x662F;&#xFF0C;&#x6B64;&#x5904;&#x7684;<code>context</code>&#x4E3A;<code>FormTestRoute</code>&#x7684;context&#xFF0C;&#x800C;<code>Form.of(context)</code>&#x662F;&#x6839;&#x636E;&#x6240;&#x6307;&#x5B9A;<code>context</code>&#x5411;&#x6839;&#x53BB;&#x67E5;&#x627E;&#xFF0C;&#x800C;<code>FormState</code>&#x662F;&#x5728;<code>FormTestRoute</code>&#x7684;&#x5B50;&#x6811;&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x884C;&#x3002;&#x6B63;&#x786E;&#x7684;&#x505A;&#x6CD5;&#x662F;&#x901A;&#x8FC7;<code>Builder</code>&#x6765;&#x6784;&#x5EFA;&#x767B;&#x5F55;&#x6309;&#x94AE;&#xFF0C;<code>Builder</code>&#x4F1A;&#x5C06;<code>widget</code>&#x8282;&#x70B9;&#x7684;<code>context</code>&#x4F5C;&#x4E3A;&#x56DE;&#x8C03;&#x53C2;&#x6570;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token function">Expanded</span><span class="token punctuation">(</span>
 <span class="token comment">// &#x901A;&#x8FC7;Builder&#x6765;&#x83B7;&#x53D6;RaisedButton&#x6240;&#x5728;widget&#x6811;&#x7684;&#x771F;&#x6B63;context(Element) </span>
  child<span class="token punctuation">:</span><span class="token function">Builder</span><span class="token punctuation">(</span>builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">RaisedButton</span><span class="token punctuation">(</span>
      <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>
      onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token comment">//&#x7531;&#x4E8E;&#x672C;widget&#x4E5F;&#x662F;Form&#x7684;&#x5B50;&#x4EE3;widget&#xFF0C;&#x6240;&#x4EE5;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x4E0B;&#x9762;&#x65B9;&#x5F0F;&#x83B7;&#x53D6;FormState  </span>
        <span class="token keyword">if</span><span class="token punctuation">(</span>Form<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">validate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">{</span>
          <span class="token comment">//&#x9A8C;&#x8BC1;&#x901A;&#x8FC7;&#x63D0;&#x4EA4;&#x6570;&#x636E;</span>
        <span class="token punctuation">}</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span>
</code></pre>
<p>&#x5176;&#x5B9E;<code>context</code>&#x6B63;&#x662F;&#x64CD;&#x4F5C;Widget&#x6240;&#x5BF9;&#x5E94;&#x7684;<code>Element</code>&#x7684;&#x4E00;&#x4E2A;&#x63A5;&#x53E3;&#xFF0C;&#x7531;&#x4E8E;Widget&#x6811;&#x5BF9;&#x5E94;&#x7684;<code>Element</code>&#x90FD;&#x662F;&#x4E0D;&#x540C;&#x7684;&#xFF0C;&#x6240;&#x4EE5;<code>context</code>&#x4E5F;&#x90FD;&#x662F;&#x4E0D;&#x540C;&#x7684;&#xFF0C;&#x6709;&#x5173;<code>context</code>&#x7684;&#x66F4;&#x591A;&#x5185;&#x5BB9;&#x4F1A;&#x5728;&#x540E;&#x9762;&#x9AD8;&#x7EA7;&#x90E8;&#x5206;&#x8BE6;&#x7EC6;&#x8BA8;&#x8BBA;&#x3002;Flutter&#x4E2D;&#x6709;&#x5F88;&#x591A;&#x201C;of(context)&#x201D;&#x8FD9;&#x79CD;&#x65B9;&#x6CD5;&#xFF0C;&#x8BFB;&#x8005;&#x5728;&#x4F7F;&#x7528;&#x65F6;&#x4E00;&#x5B9A;&#x8981;&#x6CE8;&#x610F;<code>context</code>&#x662F;&#x5426;&#x6B63;&#x786E;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="radio_and_checkbox.html" class="navigation navigation-prev " aria-label="Previous page: 3.6：单选框和复选框">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="progress.html" class="navigation navigation-next " aria-label="Next page: 3.8：进度指示器">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3.7：输入框和表单","level":"2.3.7","depth":2,"next":{"title":"3.8：进度指示器","level":"2.3.8","depth":2,"path":"chapter3/progress.md","ref":"chapter3/progress.md","articles":[]},"previous":{"title":"3.6：单选框和复选框","level":"2.3.6","depth":2,"path":"chapter3/radio_and_checkbox.md","ref":"chapter3/radio_and_checkbox.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://pcdn.flutterchina.club/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"wendux 824783146@qq.com","bookRoot":"https://book.flutterchina.club/","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter3/input_and_form.md","mtime":"2019-10-18T03:44:10.316Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-05-05T06:01:05.405Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://pcdn.flutterchina.club/gitbook/gitbook.js"></script>
    <script src="https://pcdn.flutterchina.club/gitbook/theme.js"></script>
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://pcdn.flutterchina.club/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script src="https://pcdn.flutterchina.club/gitbook/pub.js"></script>
</body>

</html>

